﻿using Domain;
using ErrorCode;
using MediatR;
using SqlSugar;
using WriteAPI.Command.Material;
using WriteAPI.Command.生产计划;

namespace WriteAPI.CommandHandle.生产计划
{
    public class DelProductionPlanCommandHandler : IRequestHandler<DelProductionPlanCommand, APIResult<object>>
    {
        private readonly ISqlSugarClient db;






        /// <summary>
        /// 构造函数
        /// </summary>
        public DelProductionPlanCommandHandler(ISqlSugarClient db)
        {
            this.db = db;
        }

        /// <summary>
        /// 处理删除请求
        /// </summary>
        public async Task<APIResult<object>> Handle(DelProductionPlanCommand request, CancellationToken cancellationToken)
        {
            var result = new APIResult<object>();


            // 删除主表记录
            int masterCount = await db.Deleteable<Lwp_ProductionPlan>()
                .Where(x => x.Id == request.Id)
                .ExecuteCommandAsync();


            result.Code = 200;
            result.Message = "删除成功";



            return result;
        }
    }
}
